package code.class3.easy;

/**
 * https://leetcode.cn/problems/lexicographically-smallest-palindrome/description/
 * 字典序最小回文串
 */
public class Code02_makeSmallestPalindrome {
    public static void main(String[] args) {
        String str = "abcd";
        String res = makeSmallestPalindrome(str);
        System.out.println(res);
    }

    public static String makeSmallestPalindrome(String s) {
        char[] arr = s.toCharArray();
        int p1 = 0, p2 = arr.length - 1;
        while (p1 <= p2) {
            if (arr[p1] != arr[p2]) {
                // 取字典序最小的值重新赋值
                arr[p2] = arr[p1] = (char) Math.min(arr[p1], arr[p2]);
            }
            p1++;
            p2--;
        }
        return new String(arr);
    }


}
